home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / lib / mathlib / libfft / TRY / c_speed3d.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  4.2 KB  |  208 lines

  1. #include <stdio.h>
  2. #include <sys/time.h>
  3.  
  4. #include "fft.h"
  5. #include "constant.h"
  6.  
  7. /*
  8. *   Precision Dependant declarations
  9. */
  10.  
  11. #ifdef ZOMPLEX
  12.  
  13. typedef zomplex this_type;
  14. typedef double this_half;
  15.  
  16. #define        TOLERANCE        DTOLERANCE
  17. #define        THIS_GEN        zgen_
  18. #define        THIS_FFTI        zfft3di
  19. #define        THIS_SCAL        zscal3d
  20. #define        THIS_FFT        zfft3d
  21.  
  22. #endif
  23.  
  24. #ifdef COMPLEX
  25.  
  26. typedef complex this_type;
  27. typedef float this_half;
  28.  
  29. #define        TOLERANCE        STOLERANCE
  30. #define        THIS_GEN        cgen_
  31. #define        THIS_FFTI        cfft3di
  32. #define        THIS_SCAL        cscal3d
  33. #define        THIS_FFT        cfft3d
  34.  
  35. #endif
  36.  
  37. /*    */
  38.  
  39. void inimat_();
  40. void GetArguments();
  41. void get_values();
  42.  
  43. int min_size, max_size, inc_size, size, size_x, size_y, size_z;
  44. this_type *pa, *pSave, *pt;
  45.  
  46. int is_timing;
  47.  
  48. static     long z_sec, z_usec;
  49. static int first_time = 1;
  50.  
  51. float second()
  52. {
  53.         struct timeval s_val;
  54.     struct timezone s_z;
  55.     float time;
  56.     long n_sec, n_usec;
  57.         gettimeofday(&s_val, &s_z);
  58.     n_sec = s_val.tv_sec;
  59.     n_usec = s_val.tv_usec;
  60.     if( first_time ) {
  61.         z_sec = n_sec;
  62.         z_usec = n_usec;
  63.         first_time =0;
  64.     }
  65.     time = (float)(n_sec-z_sec) + (float)(n_usec -z_usec) * 1.0E-6;
  66.     return( time );
  67. }
  68.  
  69. main(argc,argv)
  70. int argc;
  71. char *argv[];
  72. {
  73.     int i, j, k, n_total, is_wrong, nx, ny, nz, inc, n_times, n_flops, ld1, ld2;
  74.     double x, y, t, emax;
  75.     this_half ratio;
  76.  
  77. /* ******************************************************* */
  78.     GetArguments( argc, argv);
  79. /* ******************************************************* */
  80.  
  81.     srandom( (123*getpid()) | 0x01);
  82.  
  83.     for( size=min_size ; size <= max_size ; size += inc_size) { 
  84.  
  85.     nx = (size_x) ? size_x : size;
  86.     ny = (size_y) ? size_y : size;
  87.     nz = (size_z) ? size_z : size;
  88.     ld1 = nx+1;
  89.     ld2 = ny+1;
  90.     n_total = ld1*ld2*nz;
  91.     pa = (this_type *)malloc( (n_total + ny + nx + nz + 3*FACTOR_SPACE) * sizeof(this_type));
  92.     if( !(pa) ) {
  93.         fprintf( stderr, "Could not allocate ... Exiting\n");
  94.         exit (-1);
  95.     }
  96.  
  97.     fflush(stdout);
  98.  
  99.     printf( "%4d  ", size);
  100.  
  101.     n_flops = (int) (5. * (double)(nx*ny*nz) * (log((double)(nx*ny*nz))/log(2.)));
  102.     n_times = (int) (MAX_FLOPS / (double)n_flops);
  103.     if(n_times < 1) n_times =1;
  104.     ratio = 1./(double)(nx*ny*nz);
  105. /* *******************************************************
  106. ******************************************************* */
  107.     pSave = pa + n_total;
  108.  
  109.     THIS_GEN(pa, &n_total);
  110.     pSave = THIS_FFTI( nx,ny,nz, pSave);
  111.  
  112.     inc =1 ;
  113.  
  114.     t = second();
  115.     for ( i = 0 ; i < n_times ; i++)  {
  116.         is_wrong = THIS_FFT( -1, nx, ny, nz, pa, ld1, ld2, pSave);
  117.         is_wrong = THIS_FFT(  1, nx, ny, nz, pa, ld1, ld2, pSave);
  118.         THIS_SCAL( nx, ny, nz, ratio, pa, ld1, ld2);
  119.     }
  120.     t = second() - t;
  121.  
  122.     if( is_timing)
  123.         x = t / (double)(2*n_times);
  124.     else
  125.         x = (t > 0) ? (((double)(2*n_times) * (double)(n_flops)*1.e-6) / t) : 0.0;
  126.  
  127.     printf("%6.3g  ", x);
  128. /* *******************************************************
  129. ******************************************************* */
  130.     printf("\n");
  131.     free(pa);
  132.     }
  133. return(0);
  134. }
  135.  
  136. int is_random;
  137.  
  138. void GetArguments( argc, argv)
  139. int argc;
  140. char *argv[];
  141. {
  142.     int i, j, k;
  143.     int nerror = 0;
  144.  
  145. #define ON    1
  146.  
  147.     max_size = MAX_SIZE;
  148.     min_size = MIN_SIZE;
  149.     inc_size = INC_SIZE;
  150.  
  151.     is_timing = 0;
  152.     size_x = 0;
  153.     size_y = 0;
  154.     size_z = 0;
  155.  
  156. /* ******************************************************* */
  157.     for ( i = 1 ; (i < argc) && (nerror != ON) ; i ++ ) {
  158.     if( argv[i][0] == '-') {
  159.         switch ( argv[i][1]) {
  160.         case 'x' :
  161.         case 'X' :  
  162.                 if( i+1 > argc)
  163.                 nerror = ON;
  164.                 else
  165.                 size_x = atoi( argv[++i]);
  166.                 break;
  167.         case 'y' :
  168.         case 'Y' :  
  169.                 if( i+1 > argc)
  170.                 nerror = ON;
  171.                 else
  172.                 size_y = atoi( argv[++i]);
  173.                 break;
  174.         case 'z' :
  175.         case 'Z' :  
  176.                 if( i+1 > argc)
  177.                 nerror = ON;
  178.                 else
  179.                 size_z = atoi( argv[++i]);
  180.                 break;
  181.         case 't' :
  182.         case 'T' :  
  183.                 is_timing = 1;
  184.                 break;
  185.         default  :  nerror = ON;
  186.         }
  187.     }
  188.     else {
  189.         if( i+1 > argc)
  190.         nerror = ON;
  191.         else { 
  192.         min_size = atoi( argv[i++]);
  193.         max_size = atoi( argv[i++]);
  194.         inc_size = atoi( argv[i]);
  195.         }
  196.     }
  197.     }
  198.     if( nerror == ON) {
  199.     fprintf( stderr, 
  200.         "Usage : %s [-p(arallel)] [n_trials]\n", argv[0]);
  201.     exit(-1);
  202.     }
  203.     if ( is_timing) 
  204.         fprintf( stderr, "Checking Performance   in Secs\n");
  205.     else
  206.         fprintf( stderr, "Checking Performance   in Mflops\n");
  207. }
  208.